#include "sys.h"
#include "ff.h"
#include "ftl.h" 
#include "Pic_Process.h"
#include "usart.h"
#include "usbd_cdc.h"
#include "sdmmc_sdcard.h"
extern FATFS SD_fatfs;
extern FIL sd_file;
extern __ALIGN_BEGIN USBD_HandleTypeDef    USB_OTG_dev __ALIGN_END ;
	char OldPath[20] = "0:";
	char NewPath[20] = "";
	char str[20] = "";
//新建目录
void MKdir(char *addr)
{
	f_mkdir(addr);
}
//删除文件夹
void UNdir(char *addr)
{
	f_unlink(addr);
}
//BMP文件写入
//void BMP_W(u8 num ,u8 )
//CFG文件写入
void CFGBMP_W(u8 *buff,u32 sleek ,u32 NUM,u8 CFGorBMP,u8 num)
{
	//u8 ToFlag[6]={0};	
	if(CFGorBMP == 1)         //CFG文件
	{
		f_open(&sd_file, "0:PGconfig1.CFG", FA_WRITE);    //打开文件 只读
		f_lseek(&sd_file,sleek);
		f_write(&sd_file,buff,NUM,&br);
		f_close(&sd_file);    //关闭文件
	}
	else if(CFGorBMP == 0)
	{
		strcpy(NewPath,OldPath);
		sprintf(str,"%d",num);
		strcat(NewPath,str);
		f_open(&sd_file, strcat(NewPath,".bmp"), FA_WRITE);    
		f_lseek(&sd_file,sleek);
		f_write(&sd_file,buff,NUM,&br);
		f_close(&sd_file);    
	}  
}
//SD卡初始化
char initSD(u8 Flag,u8 num)
{

		if(SD_Init()!=0)  //为0初始化成功 非0失败
		{
			//LED4_LOW;
		}
		if(f_mount(&SD_fatfs,"0:",1) == FR_OK)		//SD卡挂载
		{
			if(Flag == 1)
			{
				f_open(&sd_file, "0:PGconfig1.CFG", FA_CREATE_NEW);   
				f_close(&sd_file);    
			}
			else if(Flag == 0)
			{
				strcpy(NewPath,OldPath);
				sprintf(str,"%d",num);
				strcat(NewPath,str);
				f_open(&sd_file, strcat(NewPath,".bmp"), FA_CREATE_NEW);  
				f_close(&sd_file);   
			}

			return 1;
		}
		else													
			return 0;

}


